package cn.enilu.guns.admin.equipment.transform;

import cn.enilu.guns.admin.common.constant.device.ColumnConstant;
import cn.enilu.guns.admin.common.constant.device.ParamConstant;
import cn.enilu.guns.admin.core.util.EntranceDataUtil;
import cn.enilu.guns.admin.equipment.dto.DeviceInfo;
import cn.enilu.guns.bean.dto.RealTimeRecordDto;
import cn.enilu.guns.bean.entity.door.EventRecord;
import com.jwz.app.DateUtils;
import com.oracle.jrockit.jfr.EventInfo;

import java.util.Map;

public class GetDeviceDataTransform{
    /**
     * 从设备中读取的数据转换为事件记录
     * @param deviceData
     */
    public static EventRecord transformToEventRecord(String deviceData) {
        String[] deviceDatas = deviceData.split(",");
        EventRecord eventRecord = new EventRecord();
        eventRecord.setCardNo(Long.parseLong(deviceDatas[0]));
        eventRecord.setPin(Long.parseLong(deviceDatas[1]));
        eventRecord.setVerified(deviceDatas[2]);
        eventRecord.setDoorId(Integer.valueOf(deviceDatas[3]));
        eventRecord.setEventType(deviceDatas[4]);
        eventRecord.setInoutState(deviceDatas[5]);
        eventRecord.setTimeSecond(DateUtils.convertStr2Date(deviceDatas[6]));
        return eventRecord;
    }

    /**
     * 从设备中读取的数据转换为实时监控记录
     * @param deviceData
     */
    public static RealTimeRecordDto transformToRealTimeRecord(String deviceData) {
        String[] records = deviceData.split(",");
        RealTimeRecordDto realTimeRecordDto = new RealTimeRecordDto();
        realTimeRecordDto.setTimeSecond(records[0]);
        realTimeRecordDto.setPin(Long.parseLong(records[1]));
        realTimeRecordDto.setCardNo(Long.parseLong(records[2]));
        realTimeRecordDto.setDoorId(Integer.valueOf(records[3]));
        realTimeRecordDto.setEventType(records[4]);
        realTimeRecordDto.setInoutState(records[5]);
        realTimeRecordDto.setVerified(records[6]);
        return realTimeRecordDto;
    }

    /**
     * 从设备中读取的数据转换为搜索设备信息
     * @param deviceData
     */
    public static DeviceInfo transformToDeviceInfo(String deviceData) {
        Map<String,String> map = EntranceDataUtil.parseParams(deviceData);
        DeviceInfo deviceInfo = new DeviceInfo();
        deviceInfo.setIpAddress(map.get(ParamConstant.SEARCH_IP));
        deviceInfo.setGateipAddress(map.get(ParamConstant.GATE_IP_ADDRESS));
        deviceInfo.setNetMask(map.get(ParamConstant.NET_MASK));
        deviceInfo.setSerisalNumber(map.get(ParamConstant.SEARCH_SN));
//        deviceInfo.setLockCount(map.get(ParamConstant.LOCK_COUNT));
        deviceInfo.setMac(map.get(ParamConstant.SEARCH_MAC));
        deviceInfo.setDeviceType(map.get(ParamConstant.SEARCH_DEVICE));
        return deviceInfo;
    }

}
